/**
* 計算字串的 byte 數
*
* @return 回傳 byte 數
*/
String.prototype.getStringBytes = function() {
return this.replace(/[^\x00-\xff]/g,"xx").length;
};
/**
* 計算字串的 byte 數
*
* @return 回傳 byte 數
*/
String.prototype.getStringChars = function() {
var cnt = 0;
for (var i = 0; i < this.length; i++) {
var c = this.charAt(i);
if (/^[\u0000-\u00ff]$/.test(c)) {
cnt++;
} else {
cnt += 2;
}
}
return cnt;
};
JS 碼如下:
var yesDateYear = "2023";
var yesDateMonth = "12";
var yesDateDay = "31";
var iDateYear = window.document.getElementById("iDateYear");
var iDateMonth = window.document.getElementById("iDateMonth");
var iDateDay = window.document.getElementById("iDateDay");
for (var i = 0; i < iDateYear.length; i++) {
if (iDateYear.options[i].value == yesDateYear) {
iDateYear.options[i].selected = true;
}
}
for (var j = 0; j < iDateMonth.length; j++) {
if (iDateMonth.options[j].value == yesDateMonth) {
iDateMonth.options[j].selected = true;
}
}
for (var k = 0; k < iDateDay.length; k++) {
if (iDateDay.options[k].value == yesDateDay) {
iDateDay.options[k].selected = true;
}
}
HTML 碼如下:
<select name="dateYear" id="iDateYear"></select>
<select name="dateMonth" id="iDateMonth"></select>
<select name="dateDate" id="iDateDay"></select>